package com.cloud.sysmana.web;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cloud.sysmana.entity.SysItem;
import com.cloud.sysmana.entity.SysRole;
import com.cloud.sysmana.ser.ISysItemService;
import com.cloud.util.base.BaseAction;
import com.cloud.util.base.RetType;
import com.cloud.util.page.PageInfo;


@Controller
@RequestMapping("system")
public class ItemAction extends BaseAction{
	
	@Resource(name="itemService")
	public ISysItemService itemService;
	
	
	/**
	 * 角色列表
	 * @return
	 */
	@RequestMapping("itemList.do")
	public String roleList(ModelMap modelMap, PageInfo pageInfo){
		
		PageInfo retPageInfo = itemService.listRolePage(pageInfo);
		modelMap.put("pageInfo", retPageInfo);
		
		return getViewsModelPathSys("sysmana/item/itemList");
	}
	
	/**
	 * 添加项目
	 * @return
	 */
	@RequestMapping("addItem.do")
	public String addItem(ModelMap modelMap, SysItem role){
		return getViewsModelPathSys("sysmana/item/addItem");
	}
	
	/**
	 * 添加或更新项目
	 * @param modelMap
	 * @param role
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping("addItem.ido")
	public RetType addOrUpdateFunc(ModelMap modelMap, SysItem role, HttpServletRequest request){
		return itemService.addOrUpdateItem(role);
	}

	
	/**
	 * 编辑角色登录
	 * @return
	 */
	@RequestMapping("editItemLogin.do")
	public String editRoleLogin(ModelMap modelMap, SysItem role){
		
		if(role != null && role.getId()>0){
			role = itemService.getItemById(role.getId());
		}
		modelMap.put("role", role);
		
		return getViewsModelPathSys("sysmana/item/editItem");
	}
	@ResponseBody
	@RequestMapping("delItem.ido")
	public RetType delItem(ModelMap modelMap,String ids){
		RetType retType = itemService.delItem(ids);
		return retType;
	}
}
